#!/bin/env python
import getpass
import qcapi
import sys

def main():
  try:
    sys.argv[1]
  except:
    print 'Usage: %s <Keyword>' % sys.argv[0]
    sys.exit(1)

  # Init
  bug = qcapi.QC()
  bug.username = raw_input('QC Username: ')
  bug.password = getpass.getpass()
  bug.qc_server = 'qc01.example.com'
  bug.qc_domainname = 'ZBH'
  bug.qc_projectname = 'ZBH_Main'

  # BG_USER_36 is the custom field for keywords
  # fields we want to see (need one at least)
  columns = ['BG_SUMMARY', 'BG_USER_36']
  search = {'BG_USER_36': '%s' % sys.argv[1]}

  try:
    result = {}
    result = bug.query(columns=columns,search=search)
  except qcapi.Error:
    sys.exit(1)

  if result.keys():
    for id in result.keys():
      print "%s: %s, Keywords %s" % (id, result[str(id)]['BG_SUMMARY'], result[str(id)]['BG_USER_36'])
  else:
    print "QC case for keyword %s not found. %s" % (sys.argv[1],results)
    


if __name__ == '__main__':
  main()
  sys.exit(0)

